@layout("/common/lyy/_container.html"){
 <div data-options="region:'north',border:false,collapsible:false,minHeight:30">
    	 <div id="toolbar" style="display: none;">
    	 		@if(shiro.hasPermission("/client/add")){
                <a onclick="openAddClient();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">添加</a>
         		@}
                </div>
        <div style="margin-top: 4px">
        <input id="searchKey" name="searchKey" '> <input id="searchWord"
                name="searchWord" '>
         <label style="margin-left: 20px;">是否正常：</label><input
                id="ifUse" name="ifUse">
        </div>
    </div>
    <div data-options="region:'center',border:false,">
        <div id="mainDatagrid"></div>
    </div>
    <div id="viewWindow_orgProductSku" style="padding: 10px 20px"></div>
    <div id="addDialog" style="padding: 10px 20px">
        <div style="margin-bottom: 5px;">连锁客户信息</div>
        <form id="addForm" method="post">
            <table>
            	<tr>
                    <td align="right"><label>主键:</label></td>
                    <td><input id="id"  name="id" ></td>
                </tr>
                <tr>
                    <td align="right"><label>连锁客户编码:</label></td>
                    <td><input id="clientId"  name="clientId" ></td>
                </tr>
                <tr>
                    <td align="right"><label>连锁客户名称:</label></td>
                    <td><input id="clientName"  name="clientName" ></td>
                </tr>
                <tr>
                    <td align="right"><label>密码:</label></td>
                    <td><input  id="clientSecret" name="clientSecret"></td>
                </tr>
                 <tr>
			        <td style="text-align:right;">连锁客户状态：</td>
			        <td style="text-align:left">
			            <span class="radioSpan">
			                <input type="radio" name="clientState" value="0">正常</input>
			                <input type="radio" name="clientState" value="1">停用</input>
			            </span>
			        </td>
			    </tr>
            </table>
        </form>
    </div>
    <div id="editDialog" style="padding: 10px 20px">
        <div style="margin-bottom: 5px;">连锁客户信息</div>
        <form id="editForm" method="post">
           <table>
            	<tr>
                    <td align="right"><label>主键:</label></td>
                    <td><input id="id"  name="id" ></td>
                </tr>
                <tr>
                    <td align="right"><label>连锁客户编码:</label></td>
                    <td><input id="clientId"  name="clientId" ></td>
                </tr>
                <tr>
                    <td align="right"><label>连锁客户名称:</label></td>
                    <td><input id="clientName"  name="clientName" ></td>
                </tr>
                <tr>
                    <td align="right"><label>密码:</label></td>
                    <td><input  id="clientSecret" name="clientSecret"></td>
                </tr>
                 <tr>
			        <td style="text-align:right;">连锁客户状态：</td>
			        <td style="text-align:left">
			            <span class="radioSpan">
			                <input type="radio" name="clientState" value="0">正常</input>
			                <input type="radio" name="clientState" value="1">停用</input>
			            </span>
			        </td>
			    </tr>
            </table>
        </form>
    </div>
    
<script type="text/javascript">
	

	
	
	var searchKey;
	var searchWord;
	var ifUse;

	$(function() {
		searchKey = $('#searchKey').val();
		searchWord = $('#searchWord').val();
		$('#mainDatagrid')
				.datagrid(
						{
							url : Feng.ctxPath + "/client/selectByMsg",
							queryParams : {
								searchKey : searchKey,
								searchWord : searchWord,
								ifUse :ifUse
							},
							pagination : true,
							rownumbers : true,
							fit : true,
							fitColumns : true,
							singleSelect : true,
							border : true,
							remoteSort : false,
							pageSize : 20,
							columns : [ [ {
								field : 'id',
								title : '编号',
								sortable : true
							}, {
								field : 'clientId',
								title : '客户端id',
								sortable : true
							}, {
								field : 'clientName',
								title : '连锁客户名称',
								sortable : true
							}, {
								field : 'clientState',
								title : '连锁客户状态',
								sortable : true,
								formatter : function(value, row, index) {
									if (row.clientState != null) {
										switch (row.clientState) {
										case "0":
											return "正常";
											break;
										case "1":
											return "停用";
											break;
										
										}
									}
								}
							}, {
								field : 'clientSecret',
								title : '密码',
								sortable : true,
								hidden:'true'
							},
							{
								field : 'action',
								title : '操作',
								width : 120,
								formatter : function(value, row, index) {
									var str = '&nbsp;';
									@if(shiro.hasPermission("/client/update")){
										str += $.formatString(
														'<a href="javascript:void(0)"   class="edit">编辑</a>',
														row.resourceId);
										str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
										@}
										@if(shiro.hasPermission("/client/delete")){
										str += $.formatString(
														'<a href="javascript:void(0)"   class="del">删除</a>',
														row.resourceId);
										@}
									return str;
								}
							}] ],
							toolbar :'#toolbar'
						});

        
		
		$('#addDialog')
		.dialog(
				{
					title : '添加连锁客户',
					width : '320px',
					height : '260px',
					closed : true,
					cache : false,
					modal : true,
					buttons : [
							{
								text : '保存',
								iconCls : 'icon-save',
								handler : function() {
									var formData   = $.serializeObject($('#addForm'));    
									//applyData=JSON.parse(normalMsg);
				  					//oldDate=JSON.stringify(applyData);
				  					console.log(JSON.stringify(formData))
									if (!formData.clientId
											|| !formData.clientName
											|| !formData.clientState
											|| !formData.clientSecret) {
										Feng.error("所有字段不能为空！");
									} else {
										
										var ajax = new $ax(Feng.ctxPath + "/client/add", function (result) {
								            Feng.success("添加成功!");
															$(
																	'#addDialog')
																	.dialog(
																			'close');
								            reloadMainDataGrid();
								        }, function (data) {
								            Feng.error("添加失败!" + data.responseJSON.message + "!");
								        });
								        ajax.set(formData);
								        ajax.start();
										
										
										}
								}
							}, {
								text : '取消',
								iconCls : 'icon-cancel',
								handler : function() {
									$('#addDialog').dialog('close');
								}
							} ]
				});
		
		
		
		$('#editDialog')
		.dialog(
				{
					title : '修改连锁客户',
					width : '320px',
					height : '260px',
					closed : true,
					cache : false,
					modal : true,
					buttons : [
							{
								text : '保存',
								iconCls : 'icon-save',
								handler : function() {
									var formData   = $.serializeObject($('#editForm'));    
									//applyData=JSON.parse(normalMsg);
				  					//oldDate=JSON.stringify(applyData);
				  					console.log(JSON.stringify(formData))
									if (!formData.clientId
											|| !formData.clientName
											|| !formData.clientState
											|| !formData.clientSecret) {
										Feng.error("所有字段不能为空！");
									} else {
										
										var ajax = new $ax(Feng.ctxPath + "/client/update", function (result) {
								            Feng.success("修改成功!");
															$(
																	'#editDialog')
																	.dialog(
																			'close');
								            reloadMainDataGrid();
								        }, function (data) {
								            Feng.error("修改失败!" + data.responseJSON.message + "!");
								        });
								        ajax.set(formData);
								        ajax.start();
										
										
										}
								}
							}, {
								text : '取消',
								iconCls : 'icon-cancel',
								handler : function() {
									$('#editDialog').dialog('close');
								}
							} ]
				});
		

		$('#ifUse').combobox({
			valueField : 'id',
			textField : 'title',
			editable : false,
			value : '',
			width : 80,
			data : [ {
				title : '空',
				id : ''
			}, {
				title : '停用',
				id : '1'
			}, {
				title : '正常',
				id : '0'
			} ],
			onChange : function(newValue, oldValue) {
				ifUse = $('#ifUse').combobox('getValue');
				reloadMainDataGrid();
			}
		});
		
		$('#searchKey').combobox({
			valueField : 'id',
			textField : 'title',
			editable : false,
			value : 'clientName',
			width : 120,
			data : [ {
				title : '客户端id',
				id : 'clientId'
			}, {
				title : '连锁客户名称',
				id : 'clientName'
			} ],
			onSelect : function(record) {
				searchKey = $('#searchKey').combobox('getValue');
			}
		});
		$('#searchWord').textbox({
			buttonText : '查找',
			iconCls : 'icon-search',
			iconAlign : 'right',
			onClickButton : function() {
				reloadMainDataGrid();
			},
			onChange : function(newValue, oldValue) {
				searchKey = $('#searchKey').combobox('getValue');
				searchWord = $('#searchWord').textbox('getValue');
			}
		});

	});
	
	
	
	
	
	//事件委托
	$(document).on("click",".edit",function(){
		var row = $('#mainDatagrid')
		.datagrid('getSelected');

		if (row) {
			$('#editDialog').dialog('open');
			$('#editForm').form('clear');
		
			$('#editForm')
					.form(
							'load',
							{
								id : row.id,
								clientId : row.clientId,
								clientName : row.clientName,
								clientSecret : row.clientSecret,
								clientState : row.clientState,
							});
		} else {
			$.messager.show({
				title : '警告',
				msg : '请先选择一条记录!'
			});
		}
	        
	})
	$(document).on("click",".del",function(){
		var row = $('#mainDatagrid')
		.datagrid('getSelected');
		//console.log(row)
		//alert(row.id)
		
		 var ajax = new $ax(Feng.ctxPath + "/client/delete", function (data) {
	            Feng.success("删除成功!");
	            reloadMainDataGrid();
	        }, function (data) {
	            Feng.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("clientId",row.id);
	        ajax.start();
	        
	})
	
	
	
	
	function reloadMainDataGrid() {
		$('#mainDatagrid').datagrid("load", {
			searchKey : searchKey,
			searchWord : searchWord,
			ifUse : ifUse
		});
	}
	
	function openAddClient(){
		$('#addDialog').dialog('open');
		$('#addForm').form('clear');
		
	}
	
</script>
<script src="${ctxPath}/static/modular/ry600/client/client.js"></script>
@}